package com.blb.educourseservice.controller;

import com.blb.common.entity.CourseActivity;
import com.blb.common.util.ResponseResult;
import com.blb.educourseservice.service.CourseActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class CourseActivityController {

    @Autowired
    private CourseActivityService courseTypeService;

    /**
     * 给活动库存加1
     * @param activityId
     * @return
     */
    @RequestMapping("/course-activity/addStock")
    public ResponseResult<CourseActivity> addStock(@RequestParam Integer activityId,
                                                   @RequestParam(required = false,defaultValue = "1") Integer stock){
        CourseActivity courseActivity = courseTypeService.addStock(activityId,stock);
        return ResponseResult.ok(courseActivity);
    }

    /**
     * 给活动库存减1
     * @param activityId
     * @return
     */
    @RequestMapping("/course-activity/reduceStock")
    public ResponseResult<CourseActivity> reduceStock(@RequestParam Integer activityId,
                                                      @RequestParam(required = false,defaultValue = "1")Integer stock){
        CourseActivity courseActivity = courseTypeService.reduceStock(activityId,stock);
        return ResponseResult.ok(courseActivity);
    }
}
